home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-09 | 4.4 KB | 116 lines | [TEXT/RLAB] |
- FILES:
-
- Discussion of: Using file with `rfile' and `load' commands,
- and "file-static" variables.
-
- With the exception of the rfile command, all functions that
- manipulate files, identify the file by a string. A string is
- ALWAYS enclosed in double-quotes (`"'). The characters
- enclosed by the quotes are taken literally, thus: " filename "
- is different from "filename".
-
- Two special files that are always available are "stdout", and
- "stderr". They can be used like ordinary files with any
- command that takes a filename as an argument.
-
- Input and output in RLaB is handled through a list of open
- files. When fprintf(), read(), write() or load() are called
- the list is searched to see if the file is already open. If
- the file is already open, then the proper file-handle is given
- to the function. Thus fprintf() and write() can be called many
- times without constantly opening and closing a file.
-
- If the user wants to explicitly close a file, the close()
- function can be called.
-
- The rfile and load commands close their file after each
- invocation so that someone modifying an rfile can keep
- re-loading it without having to constantly type
- `close("file")'.
-
- if the 1st character of the string is the `|' then a pipe to
- the process denoted by the remainder of the string is created.
- close() can also be used to explicitly close a pipe.
-
- Examples:
-
- write( "stdout", rand(3,3) )
-
- The above writes a 3x3 random matrix the the standard output.
- Usually this is the screen.
-
- write( "stdout", list )
-
- If `list' is an RLaB list-object then the entire contents of
- the list are output to the screen.
-
- fprintf( " myfile" , "%s", "sample string");
-
- The above will write the string to the file ` myfile'. This
- file will be difficult to deal with because of the leading
- space.
-
- write ( "| lpr", a, b, c );
-
- The above will open a pipe to lpr, and write a, b, and c to
- the stdin of lpr. The RLaB plot function makes extensive use
- of this feature to run GNUPLOT as a sub-process and sends all
- plot commands to GNUPLOT through a pipe. If you want to pipe
- data to several similar processes, then you need to make the
- string unique. For instance:
-
- fprintf ("|gnuplot", "set term vttek\n");
-
- will send the command "set term vttek\n" to a gnuplot
- sub-process. If you want to run multiple gnuplot sub-process
- then you must distinguish the string identifies:
-
- fprintf ("|gnuplot # p1", "set term vttek\n");
- fprintf ("|gnuplot # p2", "set term X11\n");
-
- will run two unique gnuplot sub-processes.
-
- --------------------------------------------------------------
-
- File-static variable are variables that are visible only to
- other statements, or functions within that particular file,
- after the static declaration. File-static variables are
- declared with the statement:
-
- static (var1, var2, var3)
-
- which is similar to the local declaration. there can be one or
- more variables declared within the static statement. Multiple
- static statements can be used within a file. The variable(s)
- declared static do not become static until after the static
- declaration.
-
- --------------------------------------------------------------
-
- RLaB does not automatically load rfiles in your path, like
- MATLAB. Instead, you must load the files manually. You can do
- this either with the `load' function, or with the `rfile'
- command. The rfile command is easier, cause it searches your
- path so you don't have to give it a full pathname (or the .r
- extension).
-
- Typing `rfile' will show you the rfiles in your path. If you
- compiled it with the default path you will see the pwd, and a
- toolbox directory, and the rlib directory. All the files in
- the rlib directory are automatically loaded on startup, so
- having it in your path is somewhat redundant (you can remove
- it if you like).
-
- With RLaB you can see all the functions that are in the
- workspace by typing `what()', and all the variables by typing
- `who()'. If a function you want to use does not show up when
- you type `what()', then it must be loaded via `rfile', or
- `load()'. If there is a function you use alot, move it the
- rlib directory, and it will get loaded automatically on
- startup. Keep a copy in a safe place though, cause a new rlab
- release will wipe it out. Or, you can define the environment
- variable RLAB_LIB_DIR, for rlab to search at startup instead
- of the compiled in directory.
-
- See Also: printf, fprintf, read, write, close, rfile
-